﻿using System;
using System.Linq;
using System.Text;
using PayrollSystemLibrary.DTO;
using PayrollSystemLibrary.Model;

namespace PayrollSystemLibrary
{
    public class EmployeeService
    {
        public AddEmployeeResult AddEmployee (AddEmployeeInfo info)
        {
            var employeeHelper = new EmployeeHelper();
            var emp = employeeHelper.CreateFrom(info);
            var result = employeeHelper.Validate(emp);
            if (result.IsValid)
            {
                using (var db = new DataAccessHelper())
                {
                    db.Add(emp);
                    db.Save();
                }
                return new AddEmployeeResult() {EmployeeId = emp.EmpId, ValidationResult = null, IsValid = true};
            }
            else
            {
                return new AddEmployeeResult() { EmployeeId =-1, ValidationResult = result.ValidationResult, IsValid = false };   
            }

        }

    }
}
